package pl.dsp.dsp1.processing;

public class IDFTGenerator implements Generator {

	private Signal signal;

	public IDFTGenerator(Signal signal) {
		this.signal = signal;
	}

	@Override
	public SignalValue at(double x) {
		int m = (int) (x / signal.getSamplingPeriod());
		int N = signal.size();
		
		SignalValue result = new ComplexValue(0,0);
		
		for(int n = 0; n < N; n++)
		{
			result = result.add(ComplexValue.euler(2*Math.PI*m*n/N).multiply(signal.get(n)));
		}
		
		return result;
	}

	@Override
	public boolean isPeriodical() {
		return false;
	}

}
